<?php

class Video_model extends  Model {


    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }


    public function get_video_list($limit,$start) {        
         try{
            $video_sql = "SELECT *
                                    FROM tbl_videos";
            $video_sql.= " limit ".$start.",".$limit;
        $video = $this->db->query($video_sql);
        if($video->num_rows() > 0) {
                 return $video_result = $video->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_video_list_count() {
         try{
            $video_sql = "SELECT count(*) as count
                                    FROM tbl_videos";
        $video = $this->db->query($video_sql);
        if($video->num_rows() > 0) {
                  $video_result = $video->row_array();
                  return $video_result["count"];
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
     
     public function addnewvideo($acomdationdetails) {
        try{
                $video_sql = "INSERT INTO tbl_videos
                                              (
                                               video_title,
                                               video_code,
                                               default_video,
                                               last_updated,
                                               status
                                              )
                                       VALUES (?,?,?,?,?)";
               $this->db->query($video_sql, array(
                                             $acomdationdetails['video_title'],
                                             $acomdationdetails['video_code'],
                                             $acomdationdetails['default_video'],
                                             $acomdationdetails['last_updated'],
                                             $acomdationdetails['status'],

                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

    public function get_video_details($videoid)
    {
        
         try{
           $video_sql = "SELECT *
                                    FROM tbl_videos where id=?";
        $video = $this->db->query($video_sql, array($videoid));
        if($video->num_rows() > 0) {
            //print_r($video->row_array());
                 return $video_result = $video->row_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
     public function doeditvideo($acomdationdetails) {
      //   print_r($acomdationdetails);exit;
        try{
                $video_sql = "update tbl_videos set video_title=?,video_code=?,default_video=?,last_updated=?,status=?  where id=?";
               $this->db->query($video_sql, array(
                                             $acomdationdetails['video_title'],
                                             $acomdationdetails['video_code'],
                                             $acomdationdetails['default_video'],
                                             $acomdationdetails['last_updated'],
                                             $acomdationdetails['status'],
                                             $acomdationdetails['id']
                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

      public function deletevideo($videoid) {
      //   print_r($acomdationdetails);exit;
        try{
                $video_sql = "delete from tbl_videos  where id=?";
               $this->db->query($video_sql, array($videoid
                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }  

}
?>
